// pages/course/lp/lpItem/lpItem.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    h5Url: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '稍等',
    });
    var MsgID = options.MsgID;
    var userID = getApp().globalData.userId;
    var userName = getApp().globalData.userInfo.nickName;
    var page = this;
    var basePath = getApp().globalData.basePath.miniAppPath;
    //get token
    if (userID != "") {
      wx.request({
        url: basePath + '/wxMa/3/' + userID,
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          'Cookie': "JSESSIONID=" + getApp().globalData.sessionId
        },
        success: function (res) {
          if (res.data.token == null) {
            wx.showToast({
              title: 'token获取失败',
            });
          }
          if (res.data.code == "20") {
            wx.showToast({
              title: '服务器繁忙',
            });
          } else if (res.data.code == "22") {
            wx.showToast({
              title: '网络延迟',
            })
          } else if (res.data.code == "21") {
            var url = getApp().globalData.basePath.appPath + "/mobileweb/ShareLiveVideo/videoWX.html?userID=" + userID + "&userName=" + encodeURIComponent(userName) + "&MsgID=" + MsgID + "&userTk=" + res.data.token;
           
            page.setData({
              h5Url: url
            });
            wx.hideLoading();
          }

        }
      })
    } else {
      setTimeout(function () {
        wx.navigateBack({
          delta: 1,
        });
      }, 1000);
      wx.showToast({
        title: '请先登录',
      });
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.setData({
      h5Url: ""
    });

  },


})